home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Games / NeXTmj / Source / IntegerList.h < prev    next >
C/C++ Source or Header  |  1991-03-22  |  2KB  |  66 lines

  1.  
  2. /*
  3.  * This object provides a list that holds integers.
  4.  * This object uses an Objective-C List object to hold values.  There
  5.  *    is a problem, however, with the integer value 0.
  6.  * In the Objective-C List a 0 is nil.  Therefore 0 cannot be
  7.  *    added to the list.  To compensate for this, and utilizing the fact
  8.  *    that this object is used to hold tile indexes, an offset is added to
  9.  *    values stored on the list and subtraced when removed.
  10.  *
  11.  $Author$
  12.  $Header$
  13.  *
  14.  $Log$
  15.  */
  16.  
  17. extern "Objective-C" {
  18. #import    <objc/List.h>
  19. }
  20.  
  21.  
  22. class IntegerList {
  23.  
  24. private:
  25.                                                 // This is the Objective-C object used
  26.                                                 //    to hold a list of integers.
  27.     List    *my_list;
  28.                                                 // Used when iterating through the 
  29.                                                 //    list.
  30.     int        iterator;
  31.                                                 // We can't blindly store integers
  32.                                                 //    on the list.  They must be encoded.
  33.                                                 //    This is because 0 is a legal value
  34.                                                 //    but the list object considers it nil
  35.                                                 //    and won't place it on the list.
  36.     int        encodeValue( int ),
  37.             decodeValue( int );
  38.             
  39. public:
  40.     IntegerList( void );
  41.     ~IntegerList( void );
  42.     
  43.     
  44.                                                 // This operator indexes through the list
  45.                                                 //    starting at 0 and returning -1 when
  46.                                                 //    the end of the list is reached.
  47.                                                 // You can't perform operations on the
  48.                                                 //    list as your scanning through it.
  49.     int        operator()();
  50.                                                 // Prepare for list iteration.
  51.     void    beginIterate();
  52.                                                 // Add a integer to the list.
  53.     void    operator+=( int );
  54.                                                 // Remove a integer from this list.
  55.     void    operator-=( int );
  56.                                                 // Empty the list of all values.
  57.     void    empty( void );
  58.                                                 // Return the number of items on
  59.                                                 //    the list.
  60.     int        count( void );
  61.                                                 // Return the value of the last integer
  62.                                                 //    on the list.
  63.     int        lastValue( void );
  64. };
  65.  
  66.